//
//  NewsDetialViewModel.swift
//  知乎日报Demo
//
//  Created by Ann on 2017/10/19.
//  Copyright © 2017年 Ann. All rights reserved.
//

import Foundation
import Alamofire
//5.10 创建用来加载页面详情的Model

class NewsDetialViewModel{
    

class func loadNewsDetail(newsId:Int,finished:((_ isSuccess:Bool,_ newsDetial:NewsDetial?)->())?){
    
    //5.10.1 通过新闻ID获取新闻详情HTML页面
    Alamofire.request(NEWS_DETAIL_URL+"\(newsId)").responseJSON { (data) in
        let dataDict = data.result.value as? [String: AnyObject]
 
        
        guard dataDict != nil || data.error == nil else{
            finished?(false,nil)
            
            return
        }
  
        let detialModel = NewsDetial(dict: dataDict!)
        
        finished?(true,detialModel)
        
        
    }
    
}
/**
 
 
 
 */
class func loadNewsExtraInfo(id:Int,finished:@escaping (_ isSuccess:Bool,_ extraInfo:NewsExtra?)->()){
    
    
    Alamofire.request(NEWS_EXTRA_URL+"\(id)").responseJSON { (data) in
        let dictJson = data.result.value as? [String:AnyObject]
        
        guard dictJson != nil else {
            finished(false, nil)
            print("erre:\(data.error)")
            return
        }
        let newsExtra = NewsExtra(dict: dictJson!)
        finished(true, newsExtra)
 
    }
    
}
}
